#include "stdafx.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////
void calc_bias(tagUMyCalcFormula*pFormula,long numCalc,phistory_data paData,double*dataCalc[10],long decNum,long sec_type,_procReflection procReflection)
{
	long i=0;
	double seedPrice(__price_seed__[decNum]);
	double*fpMAClose=dataCalc[5],*pcdClose=dataCalc[9];
	double*BIAS=dataCalc[0],*MABIAS=dataCalc[1];

	for(i=0;i<numCalc;++i)
		pcdClose[i] = paData[i].ClosePx/seedPrice;

	memcpy(fpMAClose,pcdClose,numCalc*sizeof(double));
	UMyCalc_MA(fpMAClose,numCalc,pFormula->infoParam[0].nowValue);

	UMyCalc_SUB(dataCalc[3],pcdClose,fpMAClose,numCalc);
	UMyCalc_DIV(BIAS,dataCalc[3],fpMAClose,numCalc);
	UMyCalc_MUL2(BIAS,100,numCalc);

	memcpy(MABIAS,BIAS,numCalc*sizeof(double));
	UMyCalc_MA(MABIAS,numCalc,pFormula->infoParam[1].nowValue);
}
/*
	BIAS:(CLOSE-MA(CLOSE,N))/MA(CLOSE,N)*100;
	BIASMA:MA(BIAS,M);
*/

void calc_bias36(tagUMyCalcFormula*pFormula,long numCalc,phistory_data paData,double*dataCalc[10],long decNum,long sec_type,_procReflection procReflection)
{
	long i=0;
	double seedPrice(__price_seed__[decNum]);
	double*pcdClose=dataCalc[9];
	double*fpMA3=dataCalc[5],*fpMA6=dataCalc[4],*fpMA12=dataCalc[3];
	double*BIAS36=dataCalc[0],*BIAS612=dataCalc[1],*MABIAS=dataCalc[2];

	for(i=0;i<numCalc;++i)
		pcdClose[i] = paData[i].ClosePx/seedPrice;

	memcpy(fpMA3,pcdClose,numCalc*sizeof(double));
	memcpy(fpMA6,pcdClose,numCalc*sizeof(double));
	memcpy(fpMA12,pcdClose,numCalc*sizeof(double));

	UMyCalc_MA(fpMA3,numCalc,3);
	UMyCalc_MA(fpMA6,numCalc,6);
	UMyCalc_MA(fpMA12,numCalc,12);

	UMyCalc_SUB(BIAS36,fpMA3,fpMA6,numCalc);
	UMyCalc_SUB(BIAS612,fpMA6,fpMA12,numCalc);

	memcpy(MABIAS,BIAS36,numCalc*sizeof(double));
	UMyCalc_MA(MABIAS,numCalc,pFormula->infoParam[0].nowValue);
}
/*
	BIAS36:MA(CLOSE,3)-MA(CLOSE,6);
	BIAS612:MA(CLOSE,6)-MA(CLOSE,12);
	MABIAS:MA(BIAS36,M);
*/
